package com.wwg.cms.service.impl;

import java.util.Collection;
import java.util.List;

import com.wwg.cms.bo.*;
import com.wwg.cms.service.*;
import com.css.framework.dao.GeneralDao;

import com.wwg.cms.bo.entity.*;

/**
 * create by wwl
 *
 * @author wwl
 */
public class AccessitemServiceImpl implements AccessitemService {

    private GeneralDao generalDao;

    public void setGeneralDao(GeneralDao generalDao) {
        this.generalDao = generalDao;
    }


    /**
     * 获取所有
     */
    public Collection getAccessitemList() {
        String hsql = "select ent from AccessitemEntity as ent ";
        return generalDao.find(hsql);

    }

    /**
     * 添加
     *
     * @param accessitem
     * @return
     */
    public Accessitem addAccessitem(Accessitem accessitem) {

        generalDao.save(accessitem);

        return accessitem;

    }

    /**
     * 修改
     *
     * @param accessitem
     * @return
     */
    public Accessitem updateAccessitem(Accessitem accessitem) {

        generalDao.saveOrUpdate(accessitem);


        return accessitem;
    }

    /**
     * 删除
     *
     * @param accessitem
     * @return
     */
    public Accessitem deleteAccessitem(Accessitem accessitem) {
        generalDao.delete(accessitem);

        return accessitem;
    }

    /**
     * 获取 by id
     *
     * @param id 编号
     * @return
     */
    public Accessitem getAccessitemById(Long id) {


        return (Accessitem) generalDao.fetch(id, AccessitemEntity.class);

    }

    public List<Accessitem> getAccessitemsByRoleId(Long roleId) {
        String hsql = "select ent from AccessitemEntity as ent where ent.role.id=:roleId";
        return generalDao.findByNamedParam(hsql,"roleId",roleId);
    }
}
